using Config;
using Entity;
using MoonFramework.Scripts.View.Music;
using Random = UnityEngine.Random;

namespace Map.MapObject.HitObject
{
    public class TreeObject : BaseHitMapObject
    {
        public override void Init(BaseMapBlock mapBlock, ulong id)
        {
            base.Init(mapBlock, id);
            _weaponType = WeaponType.Axe;
        }

        public override bool DoHit(Actor actor, float dir)
        {
            return !(dir > 2) && base.DoHit(actor, dir);
        }

        public override void Hurt(ItemWeaponInfo weaponInfo)
        {
            if (weaponInfo.WeaponType != WeaponType.Axe) return;
            AudioManager.Instance.PlayOnShot(hurtAudioClips[Random.Range(0, hurtAudioClips.Length - 1)], transform.position).Forget();
            RotationTransform(1).Forget();
            hp -= weaponInfo.AttackValue;
            if (hp <= 0) Dead();
        }
    }
}